unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, RzPanel, RzButton, Menus;

type
  TForm1 = class(TForm)
    Btnx_1: TButton;
    Btnx_2: TButton;
    Btnx_3: TButton;
    Btnx_4: TButton;
    Tool_1: TRzToolbar;
    PopupMenu1: TPopupMenu;
    mniMENU11: TMenuItem;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
    procedure Btnx_4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure mniMENU11Click(Sender: TObject);
  private
    procedure HandleAppMsg(var Msg:TMsg;var Handled:Boolean);

  public
    procedure  WMCommand(var Message: TWMCommand); message WM_COMMAND;  
  end;

var
  Form1: TForm1;

implementation

uses
  Class_KzDebug;

{$R *.dfm}

procedure TForm1.Btnx_1Click(Sender: TObject);
begin
  ShowMessage(TButton(Sender).Name);
end;

procedure TForm1.Btnx_2Click(Sender: TObject);
begin
  ShowMessage(TButton(Sender).Name);
end;

procedure TForm1.Btnx_3Click(Sender: TObject);
begin
  ShowMessage(TButton(Sender).Name);
end;

procedure TForm1.Btnx_4Click(Sender: TObject);
begin
  ShowMessage(TButton(Sender).Name);
end;

{procedure TForm1.WndProc(var Message: TMessage);
begin
  if Message.Msg=BN_CLICKED  then
  begin
    ShowMessage('WM_LBUTTONDOWN');
  end else
  if Message.Msg=WM_LBUTTONUP then
  begin
    ShowMessage('WM_LBUTTONUP');
  end else  
  begin
    inherited;
  end;    
end;}

procedure TForm1.WMCommand(var Message: TWMCommand);
begin
  if Message.NotifyCode = BN_CLICKED  then
  begin
    if FindControl(Message.Ctl) = Btnx_1 then showmessage('click the button');
  end;
  inherited;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage:=HandleAppMsg;
end;

procedure TForm1.HandleAppMsg(var Msg: TMsg; var Handled: Boolean);
var
  TempA:string;
begin
  if (Msg.message = WM_LBUTTONDOWN) then
  begin
    TempA:=FindControl(Msg.hwnd).Name;

    KzDebug.FileFmt('%S',[TempA]);

    if UpperCase(TempA)='BTNX_4' then
    begin
      FindControl(Msg.hwnd).SetFocus;    
      ShowMessage('no permission');

      Handled:=True;
    end else
    begin
      Handled:=False;
    end;
  end;
end;

procedure TForm1.mniMENU11Click(Sender: TObject);
begin
  //Btnx_4Click(Btnx_4);
  PostMessage(Btnx_4.Handle,WM_LBUTTONDOWN,0,0);
  PostMessage(Btnx_4.Handle,WM_LBUTTONUP,0,0);
end;

end.
